﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Omega.Framework.Cameras;

namespace Omega.Editor.Classes
{
    static public class SceneViewer
    {

        static bool altPressed = false;
        static bool CntrPressed = false;
        static bool LftMousePressed = false;

        static int x, y = 0;


        static public void Init()
        {

            Editor.Controls.RenderScreen.KeyDown += RenderScreen_KeyDown;
            Editor.Controls.RenderScreen.KeyUp += RenderScreen_KeyUp;
            Editor.Controls.RenderScreen.KeyPress += RenderScreen_KeyPress;
            Editor.Controls.RenderScreen.MouseDown += RenderScreen_MouseDown;
            Editor.Controls.RenderScreen.MouseMove += RenderScreen_MouseMove;
            Editor.Controls.RenderScreen.MouseUp += RenderScreen_MouseUp;

        }

        static void RenderScreen_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            LookAtCamera c = Editor.Controls.RenderScreen.Scene.CurrentCamera as LookAtCamera;
            //d
            if (e.KeyChar == 100)
            {
                
               
            }
            //s
            if (e.KeyChar == 115)
            {
                c.MoveFront(0.05f);
                
            }
            //a
            if (e.KeyChar == 97)
            {
               // c.Rotate(0, 0, -1f, Editor.Controls.RenderScreen.OpenGL);
            }

            //w
            if (e.KeyChar == 115)
            {
               c.MoveBack(0.05f);
            }
            c.ComputeCameraPosition();
            Trace.Write(Editor.Controls.RenderScreen.Scene.CurrentCamera.Position);
        }

        static void RenderScreen_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (!e.Control && CntrPressed)
                CntrPressed = false;
            if (!e.Alt && altPressed)
                altPressed = false;
        }

        static void RenderScreen_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            LftMousePressed = false;
            x = y = 0;
        }

        static void RenderScreen_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (LftMousePressed)
                ComputeMouseMove(e);
        }

        static void RenderScreen_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            altPressed = e.Alt;
            CntrPressed = e.Control;


        }

        static void RenderScreen_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
                ComputeMouseMove(e);
        }

        private static void ComputeMouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            LookAtCamera c = Editor.Controls.RenderScreen.Scene.CurrentCamera as LookAtCamera;
            c.ComputeCameraPosition();
            c.SetRotation(Editor.Controls.RenderScreen.Width, Editor.Controls.RenderScreen.Height,
                e.X, e.Y);


        }



    }
}
